home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / term-Source.lha / termConfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-18  |  63.3 KB  |  2,774 lines

  1. /*
  2. **    termConfig.c
  3. **
  4. **    Configuration processing routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Number of chunks to stop at. */
  13.  
  14. #define    NUM_STOPS    19
  15.  
  16.     /* Reset routine function pointer. */
  17.  
  18. typedef VOID        (* RESET)(APTR,STRPTR);
  19.  
  20.     /* Local routines. */
  21.  
  22. STATIC BYTE        ReadSerialPrefs(struct SerialPrefs *Prefs);
  23.  
  24. STATIC VOID        ResetSerialConfig(struct SerialSettings *SerialConfig);
  25. STATIC VOID        ResetModem(struct ModemSettings *ModemConfig);
  26. STATIC VOID        ResetScreen(struct ScreenSettings *ScreenConfig);
  27. STATIC VOID        ResetTerminal(struct TerminalSettings *TerminalConfig);
  28. STATIC VOID        ResetEmulation(struct EmulationSettings *EmulationConfig);
  29. STATIC VOID        ResetClip(struct ClipSettings *ClipConfig);
  30. STATIC VOID        ResetCapture(struct CaptureSettings *CaptureConfig);
  31. STATIC VOID        ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer);
  32. STATIC VOID        ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer);
  33. STATIC VOID        ResetMisc(struct MiscSettings *MiscConfig);
  34. STATIC VOID        ResetCommand(struct CommandSettings *CommandConfig);
  35. STATIC VOID        ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib);
  36.  
  37. STATIC BYTE        WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password);
  38. STATIC BYTE        WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password);
  39. STATIC UBYTE        IsConfigChunk(ULONG ID);
  40. STATIC BYTE        ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password);
  41.  
  42. STATIC UWORD SizeTable[] =
  43. {
  44.     sizeof(struct SerialSettings),
  45.     sizeof(struct ModemSettings),
  46.     sizeof(struct CommandSettings),
  47.     sizeof(struct ScreenSettings),
  48.     sizeof(struct TerminalSettings),
  49.     sizeof(struct PathSettings),
  50.     sizeof(struct MiscSettings),
  51.     sizeof(struct ClipSettings),
  52.     sizeof(struct CaptureSettings),
  53.     sizeof(struct FileSettings),
  54.     sizeof(struct EmulationSettings),
  55.     sizeof(struct TransferSettings)
  56. };
  57.  
  58. STATIC RESET ResetTable[] =
  59. {
  60.     (RESET)ResetSerialConfig,
  61.     (RESET)ResetModem,
  62.     (RESET)ResetCommand,
  63.     (RESET)ResetScreen,
  64.     (RESET)ResetTerminal,
  65.     ResetPath,
  66.     (RESET)ResetMisc,
  67.     (RESET)ResetClip,
  68.     (RESET)ResetCapture,
  69.     ResetFile,
  70.     (RESET)ResetEmulation,
  71.     ResetTransfer
  72. };
  73.  
  74. STATIC ULONG TypeTable[] =
  75. {
  76.     ID_SERL,
  77.     ID_MODM,
  78.     ID_COMD,
  79.     ID_SCRN,
  80.     ID_TRML,
  81.     ID_PATH,
  82.     ID_MISC,
  83.     ID_CLIP,
  84.     ID_CPTR,
  85.     ID_FILE,
  86.     ID_EMLN,
  87.     ID_XFER
  88. };
  89.  
  90. STATIC ULONG Stops[NUM_STOPS * 2] =
  91. {
  92.     ID_TERM,ID_CAT,
  93.     ID_TERM,ID_VERS,
  94.     ID_TERM,ID_DIAL,
  95.     ID_TERM,ID_DATE,
  96.     ID_TERM,ID_PHON,
  97.     ID_TERM,ID_PSWD,
  98.  
  99.     ID_TERM,ID_SERL,
  100.     ID_TERM,ID_MODM,
  101.     ID_TERM,ID_COMD,
  102.     ID_TERM,ID_SCRN,
  103.     ID_TERM,ID_TRML,
  104.     ID_TERM,ID_PATH,
  105.     ID_TERM,ID_MISC,
  106.     ID_TERM,ID_CLIP,
  107.     ID_TERM,ID_CPTR,
  108.     ID_TERM,ID_FILE,
  109.     ID_TERM,ID_EMLN,
  110.     ID_TERM,ID_XFER,
  111.     ID_TERM,ID_WINF
  112. };
  113.  
  114. enum    {    CR_IGNORE,CR_ASCR,CR_ASCRLF };
  115. enum    {    LF_IGNORE,LF_ASLF,LF_ASLFCR };
  116.  
  117. VOID __regargs
  118. FinalFix(struct Configuration *Config,BOOLEAN IsPhonebook,LONG Version,LONG Revision)
  119. {
  120.     if(Config)
  121.     {
  122.         if(Version < 4 || (Version == 4 && Revision < 3))
  123.         {
  124.             if(Config -> TransferConfig && Config -> MiscConfig)
  125.             {
  126.                 Config -> TransferConfig -> OverridePath    = Config -> MiscConfig -> OverridePath;
  127.                 Config -> TransferConfig -> SetArchivedBit    = Config -> MiscConfig -> SetArchivedBit;
  128.                 Config -> TransferConfig -> IdentifyFiles    = Config -> MiscConfig -> IdentifyFiles;
  129.                 Config -> TransferConfig -> TransferIcons    = Config -> MiscConfig -> TransferIcons;
  130.                 Config -> TransferConfig -> PerfMeter        = Config -> MiscConfig -> PerfMeter;
  131.                 Config -> TransferConfig -> HideUploadIcon    = Config -> MiscConfig -> HideUploadIcon;
  132.             }
  133.         }
  134.     }
  135. }
  136.  
  137. VOID __regargs
  138. FixOldConfig(struct Configuration *Config,UBYTE ConfigChunkType,BOOLEAN IsPhonebook,LONG Version,LONG Revision)
  139. {
  140.     if((Version == 3 && Revision < 6) || Version < 3)
  141.     {
  142.         if(ConfigChunkType == PREF_CLIP)
  143.             Config -> ClipConfig -> ConvertLF = TRUE;
  144.  
  145.         if(ConfigChunkType == PREF_SERIAL)
  146.             Config -> SerialConfig -> UseOwnDevUnit = TRUE;
  147.  
  148.         if(ConfigChunkType == PREF_MISC)
  149.             Config -> MiscConfig -> ProtectiveMode = TRUE;
  150.  
  151.         if(ConfigChunkType == PREF_SCREEN)
  152.         {
  153.             Config -> ScreenConfig -> UsePens    = TRUE;
  154.             Config -> ScreenConfig -> Depth        = 0;
  155.             Config -> ScreenConfig -> PenColourMode    = 42;    // Avoid trouble
  156.         }
  157.  
  158.         if(ConfigChunkType == PREF_TRANSFER)
  159.         {
  160.             WORD i;
  161.  
  162.             Config -> TransferConfig -> MangleFileNames = FALSE;
  163.  
  164.             if(Config -> TransferConfig -> ASCIIUploadLibrary[0])
  165.                 Config -> TransferConfig -> ASCIIUploadType = XFER_XPR;
  166.  
  167.             if(Config -> TransferConfig -> ASCIIDownloadLibrary[0])
  168.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_XPR;
  169.  
  170.             if(Config -> TransferConfig -> TextUploadLibrary[0])
  171.                 Config -> TransferConfig -> TextUploadType = XFER_XPR;
  172.  
  173.             if(Config -> TransferConfig -> TextDownloadLibrary[0])
  174.                 Config -> TransferConfig -> TextDownloadType = XFER_XPR;
  175.  
  176.             if(Config -> TransferConfig -> BinaryUploadLibrary[0])
  177.                 Config -> TransferConfig -> BinaryUploadType = XFER_XPR;
  178.  
  179.             if(Config -> TransferConfig -> BinaryDownloadLibrary[0])
  180.                 Config -> TransferConfig -> BinaryDownloadType = XFER_XPR;
  181.  
  182.             for(i = 0 ; i < strlen(Config -> TransferConfig -> DefaultLibrary) - 6 ; i++)
  183.             {
  184.                 if(!Strnicmp(&Config -> TransferConfig -> DefaultLibrary[i],"zmodem",6))
  185.                 {
  186.                     strcpy(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  187.  
  188.                     Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  189.  
  190.                     break;
  191.                 }
  192.             }
  193.         }
  194.  
  195.         if(ConfigChunkType == PREF_MODEM)
  196.             Config -> ModemConfig -> AbortHangsUp = FALSE;
  197.  
  198.         if(ConfigChunkType == PREF_COMMAND && IsPhonebook)
  199.         {
  200.             strcpy(Config -> CommandConfig -> LoginMacro,Config -> CommandConfig -> StartupMacro);
  201.  
  202.             memset(Config -> CommandConfig -> StartupMacro,0,sizeof(Config -> CommandConfig -> StartupMacro));
  203.         }
  204.  
  205.         if(ConfigChunkType == PREF_CAPTURE)
  206.             Config -> CaptureConfig -> SearchHistory = 10;
  207.  
  208.         if(ConfigChunkType == PREF_EMULATION)
  209.         {
  210.             if(Config -> EmulationConfig -> DestructiveBackspace < 0 || Config -> EmulationConfig -> DestructiveBackspace > 2)
  211.                 Config -> EmulationConfig -> DestructiveBackspace = 1;
  212.         }
  213.     }
  214.  
  215.     if((Version == 4 && Revision < 1) || Version < 4)
  216.     {
  217.         if(ConfigChunkType == PREF_CLIP)
  218.             Config -> ClipConfig -> ConvertLF = TRUE;
  219.  
  220.         if(ConfigChunkType == PREF_SERIAL)
  221.         {
  222.             Config -> SerialConfig -> xONxOFF    = FALSE;
  223.             Config -> SerialConfig -> PassThrough    = TRUE;
  224.         }
  225.  
  226.         if(ConfigChunkType == PREF_MISC)
  227.             Config -> MiscConfig -> ProtectiveMode = TRUE;
  228.  
  229.         if(ConfigChunkType == PREF_MODEM)
  230.         {
  231.             Config -> ModemConfig -> RedialDelay    = (Config -> ModemConfig -> RedialDelay / 6) * 60 + (Config -> ModemConfig -> RedialDelay % 6) * 10;
  232.             Config -> ModemConfig -> TimeToConnect    = (Config -> ModemConfig -> TimeToConnect / 6) * 60 + (Config -> ModemConfig -> TimeToConnect % 6) * 10;
  233.             Config -> ModemConfig -> VerboseDialing    = FALSE;
  234.         }
  235.  
  236.         if(ConfigChunkType == PREF_TERMINAL)
  237.         {
  238.             switch(Config -> TerminalConfig -> SendCR)
  239.             {
  240.                 case CR_IGNORE:
  241.  
  242.                     Config -> TerminalConfig -> SendCR = EOL_IGNORE;
  243.                     break;
  244.  
  245.                 case CR_ASCR:
  246.  
  247.                     Config -> TerminalConfig -> SendCR = EOL_CR;
  248.                     break;
  249.  
  250.                 case CR_ASCRLF:
  251.  
  252.                     Config -> TerminalConfig -> SendCR = EOL_CRLF;
  253.                     break;
  254.             }
  255.  
  256.             switch(Config -> TerminalConfig -> ReceiveCR)
  257.             {
  258.                 case CR_IGNORE:
  259.  
  260.                     Config -> TerminalConfig -> ReceiveCR = EOL_IGNORE;
  261.                     break;
  262.  
  263.                 case CR_ASCR:
  264.  
  265.                     Config -> TerminalConfig -> ReceiveCR = EOL_CR;
  266.                     break;
  267.  
  268.                 case CR_ASCRLF:
  269.  
  270.                     Config -> TerminalConfig -> ReceiveCR = EOL_CRLF;
  271.                     break;
  272.             }
  273.  
  274.             switch(Config -> TerminalConfig -> SendLF)
  275.             {
  276.                 case LF_IGNORE:
  277.  
  278.                     Config -> TerminalConfig -> SendLF = EOL_IGNORE;
  279.                     break;
  280.  
  281.                 case LF_ASLF:
  282.  
  283.                     Config -> TerminalConfig -> SendLF = EOL_LF;
  284.                     break;
  285.  
  286.                 case LF_ASLFCR:
  287.  
  288.                     Config -> TerminalConfig -> SendLF = EOL_LFCR;
  289.                     break;
  290.             }
  291.  
  292.             switch(Config -> TerminalConfig -> ReceiveLF)
  293.             {
  294.                 case LF_IGNORE:
  295.  
  296.                     Config -> TerminalConfig -> ReceiveLF = EOL_IGNORE;
  297.                     break;
  298.  
  299.                 case LF_ASLF:
  300.  
  301.                     Config -> TerminalConfig -> ReceiveLF = EOL_LF;
  302.                     break;
  303.  
  304.                 case LF_ASLFCR:
  305.  
  306.                     Config -> TerminalConfig -> ReceiveLF = EOL_LFCR;
  307.                     break;
  308.             }
  309.         }
  310.  
  311.         if(ConfigChunkType == PREF_TRANSFER)
  312.         {
  313.             WORD i;
  314.  
  315.             if(Config -> TransferConfig -> ASCIIUploadLibrary[0])
  316.                 Config -> TransferConfig -> ASCIIUploadType = XFER_XPR;
  317.  
  318.             if(Config -> TransferConfig -> ASCIIDownloadLibrary[0])
  319.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_XPR;
  320.  
  321.             if(Config -> TransferConfig -> TextUploadLibrary[0])
  322.                 Config -> TransferConfig -> TextUploadType = XFER_XPR;
  323.  
  324.             if(Config -> TransferConfig -> TextDownloadLibrary[0])
  325.                 Config -> TransferConfig -> TextDownloadType = XFER_XPR;
  326.  
  327.             if(Config -> TransferConfig -> BinaryUploadLibrary[0])
  328.                 Config -> TransferConfig -> BinaryUploadType = XFER_XPR;
  329.  
  330.             if(Config -> TransferConfig -> BinaryDownloadLibrary[0])
  331.                 Config -> TransferConfig -> BinaryDownloadType = XFER_XPR;
  332.  
  333.             for(i = 0 ; i < strlen(Config -> TransferConfig -> DefaultLibrary) - 6 ; i++)
  334.             {
  335.                 if(!Strnicmp(&Config -> TransferConfig -> DefaultLibrary[i],"zmodem",6))
  336.                 {
  337.                     strcpy(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  338.  
  339.                     Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  340.  
  341.                     break;
  342.                 }
  343.             }
  344.  
  345.             switch(Config -> TransferConfig -> SendCR)
  346.             {
  347.                 case CR_IGNORE:
  348.  
  349.                     Config -> TransferConfig -> SendCR = EOL_IGNORE;
  350.                     break;
  351.  
  352.                 case CR_ASCR:
  353.  
  354.                     Config -> TransferConfig -> SendCR = EOL_CR;
  355.                     break;
  356.  
  357.                 case CR_ASCRLF:
  358.  
  359.                     Config -> TransferConfig -> SendCR = EOL_CRLF;
  360.                     break;
  361.             }
  362.  
  363.             switch(Config -> TransferConfig -> ReceiveCR)
  364.             {
  365.                 case CR_IGNORE:
  366.  
  367.                     Config -> TransferConfig -> ReceiveCR = EOL_IGNORE;
  368.                     break;
  369.  
  370.                 case CR_ASCR:
  371.  
  372.                     Config -> TransferConfig -> ReceiveCR = EOL_CR;
  373.                     break;
  374.  
  375.                 case CR_ASCRLF:
  376.  
  377.                     Config -> TransferConfig -> ReceiveCR = EOL_CRLF;
  378.                     break;
  379.             }
  380.  
  381.             switch(Config -> TransferConfig -> SendLF)
  382.             {
  383.                 case LF_IGNORE:
  384.  
  385.                     Config -> TransferConfig -> SendLF = EOL_IGNORE;
  386.                     break;
  387.  
  388.                 case LF_ASLF:
  389.  
  390.                     Config -> TransferConfig -> SendLF = EOL_LF;
  391.                     break;
  392.  
  393.                 case LF_ASLFCR:
  394.  
  395.                     Config -> TransferConfig -> SendLF = EOL_LFCR;
  396.                     break;
  397.             }
  398.  
  399.             switch(Config -> TransferConfig -> ReceiveLF)
  400.             {
  401.                 case LF_IGNORE:
  402.  
  403.                     Config -> TransferConfig -> ReceiveLF = EOL_IGNORE;
  404.                     break;
  405.  
  406.                 case LF_ASLF:
  407.  
  408.                     Config -> TransferConfig -> ReceiveLF = EOL_LF;
  409.                     break;
  410.  
  411.                 case LF_ASLFCR:
  412.  
  413.                     Config -> TransferConfig -> ReceiveLF = EOL_LFCR;
  414.                     break;
  415.             }
  416.         }
  417.     }
  418.  
  419.     if(Version == 4 && Revision < 3)
  420.     {
  421.         if(ConfigChunkType == PREF_CLIP)
  422.             Config -> ClipConfig -> ConvertLF = TRUE;
  423.  
  424.         if(ConfigChunkType == PREF_SERIAL)
  425.         {
  426.             Config -> SerialConfig -> xONxOFF    = FALSE;
  427.             Config -> SerialConfig -> PassThrough    = TRUE;
  428.         }
  429.  
  430.         if(ConfigChunkType == PREF_MISC)
  431.             Config -> MiscConfig -> ProtectiveMode = TRUE;
  432.  
  433.         if(ConfigChunkType == PREF_TRANSFER)
  434.         {
  435.             WORD i;
  436.  
  437.             for(i = 0 ; i < strlen(Config -> TransferConfig -> DefaultLibrary) - 6 ; i++)
  438.             {
  439.                 if(!Strnicmp(&Config -> TransferConfig -> DefaultLibrary[i],"zmodem",6))
  440.                 {
  441.                     strcpy(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  442.  
  443.                     Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(Config -> TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  444.  
  445.                     break;
  446.                 }
  447.             }
  448.  
  449.             if(Config -> TransferConfig -> ASCIIUploadLibrary[0])
  450.                 Config -> TransferConfig -> ASCIIUploadType = XFER_XPR;
  451.  
  452.             if(Config -> TransferConfig -> ASCIIDownloadLibrary[0])
  453.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_XPR;
  454.  
  455.             if(Config -> TransferConfig -> InternalASCIIUpload)
  456.                 Config -> TransferConfig -> ASCIIUploadType = XFER_INTERNAL;
  457.  
  458.             if(Config -> TransferConfig -> InternalASCIIDownload)
  459.                 Config -> TransferConfig -> ASCIIDownloadType = XFER_INTERNAL;
  460.  
  461.             if(Config -> TransferConfig -> TextUploadLibrary[0])
  462.                 Config -> TransferConfig -> TextUploadType = XFER_XPR;
  463.  
  464.             if(Config -> TransferConfig -> TextDownloadLibrary[0])
  465.                 Config -> TransferConfig -> TextDownloadType = XFER_XPR;
  466.  
  467.             if(Config -> TransferConfig -> BinaryUploadLibrary[0])
  468.                 Config -> TransferConfig -> BinaryUploadType = XFER_XPR;
  469.  
  470.             if(Config -> TransferConfig -> BinaryDownloadLibrary[0])
  471.                 Config -> TransferConfig -> BinaryDownloadType = XFER_XPR;
  472.         }
  473.     }
  474. }
  475.  
  476. VOID __regargs
  477. FixScreenPens(struct ScreenSettings *ScreenConfig)
  478. {
  479.     WORD i,Count;
  480.  
  481.     for(Count = 0, i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  482.     {
  483.         if(ScreenConfig -> PenArray[i])
  484.             Count++;
  485.     }
  486.  
  487.     if(!Count)
  488.         ScreenConfig -> UsePens = TRUE;
  489. }
  490.  
  491.     /* ReadSerialPrefs():
  492.      *
  493.      *    Reads the default serial preferences settings.
  494.      */
  495.  
  496. STATIC BYTE
  497. ReadSerialPrefs(struct SerialPrefs *Prefs)
  498. {
  499.     struct IFFHandle    *Handle;
  500.     BYTE             Success = FALSE;
  501.     LONG             Error = 0;
  502.  
  503.         /* Allocate an IFF handle. */
  504.  
  505.     if(Handle = AllocIFF())
  506.     {
  507.             /* Open the preferences settings file. */
  508.  
  509.         if(Handle -> iff_Stream = Open("ENV:sys/serial.prefs",MODE_OLDFILE))
  510.         {
  511.                 /* Make it known as a DOS file handle. */
  512.  
  513.             InitIFFasDOS(Handle);
  514.  
  515.                 /* Open the file for reading. */
  516.  
  517.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  518.             {
  519.                     /* Stop at the `body' chunk. */
  520.  
  521.                 if(!(Error = StopChunk(Handle,ID_PREF,ID_SERL)))
  522.                 {
  523.                         /* Look for it... */
  524.  
  525.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  526.                     {
  527.                             /* Read the data. */
  528.  
  529.                         if(ReadChunkBytes(Handle,Prefs,sizeof(struct SerialPrefs)) == sizeof(struct SerialPrefs))
  530.                             Success = TRUE;
  531.                         else
  532.                             Error = IoErr();
  533.                     }
  534.                 }
  535.  
  536.                     /* Close the handle. */
  537.  
  538.                 CloseIFF(Handle);
  539.             }
  540.  
  541.                 /* Release the handle. */
  542.  
  543.             Close(Handle -> iff_Stream);
  544.         }
  545.         else
  546.             Error = IoErr();
  547.  
  548.             /* Clean up. */
  549.  
  550.         FreeIFF(Handle);
  551.     }
  552.     else
  553.         Error = ERR_NO_MEM;
  554.  
  555.     if(Error)
  556.         SetIoErr(Error);
  557.  
  558.         /* Return sucess/failure. */
  559.  
  560.     return(Success);
  561. }
  562.  
  563. STATIC VOID
  564. ResetSerialConfig(struct SerialSettings *SerialConfig)
  565. {
  566.     STATIC BYTE            SerialPrefsRead        = FALSE,
  567.                     SerialPrefsReadFailed    = FALSE;
  568.     STATIC struct SerialPrefs    SerialPrefs;
  569.  
  570.         /* The program will only try to read the preferences
  571.          * settings once; if the first access failed, no
  572.          * other accesses will be made.
  573.          */
  574.  
  575.     if(!SerialPrefsRead && !SerialPrefsReadFailed)
  576.         SerialPrefsReadFailed = ReadSerialPrefs(&SerialPrefs) ^ TRUE;
  577.  
  578.         /* Did we succeed in reading the file? */
  579.  
  580.     if(!SerialPrefsRead)
  581.     {
  582.         SerialConfig -> BaudRate        = 19200;
  583.         SerialConfig -> BitsPerChar        = 8;
  584.         SerialConfig -> Parity            = PARITY_NONE;
  585.         SerialConfig -> StopBits        = 1;
  586.         SerialConfig -> HandshakingProtocol    = HANDSHAKING_RTSCTS_DSR;
  587.         SerialConfig -> SerialBufferSize    = 32768;
  588.     }
  589.     else
  590.     {
  591.             /* Fill in the common data. */
  592.  
  593.         SerialConfig -> BaudRate        = SerialPrefs . sp_BaudRate;
  594.         SerialConfig -> SerialBufferSize    = SerialPrefs . sp_InputBuffer;
  595.         SerialConfig -> BitsPerChar        = SerialPrefs . sp_BitsPerChar;
  596.         SerialConfig -> StopBits        = SerialPrefs . sp_StopBits;
  597.  
  598.             /* Convert the handshaking mode. */
  599.  
  600.         switch(SerialPrefs . sp_InputHandshake)
  601.         {
  602.             case HSHAKE_NONE:
  603.  
  604.                 SerialConfig -> HandshakingProtocol = HANDSHAKING_NONE;
  605.  
  606.                 break;
  607.  
  608.             case HSHAKE_RTS:
  609.  
  610.                 SerialConfig -> HandshakingProtocol = HANDSHAKING_RTSCTS_DSR;
  611.  
  612.                 break;
  613.  
  614.             default:
  615.  
  616.                 SerialConfig -> HandshakingProtocol = HANDSHAKING_NONE;
  617.  
  618.                 break;
  619.         }
  620.  
  621.             /* Convert the parity settings. */
  622.  
  623.         if(SerialPrefs . sp_Parity <= PARITY_SPACE)
  624.             SerialConfig -> Parity = SerialPrefs . sp_Parity;
  625.         else
  626.             SerialConfig -> Parity = PARITY_NONE;
  627.  
  628.         SerialPrefsRead = TRUE;
  629.     }
  630.  
  631.     strcpy(SerialConfig -> SerialDevice,SERIALNAME);
  632.  
  633.     SerialConfig -> Duplex        = DUPLEX_FULL;
  634.     SerialConfig -> HighSpeed    = FALSE;
  635.     SerialConfig -> Shared        = FALSE;
  636.     SerialConfig -> BreakLength    = 250000;
  637.     SerialConfig -> UnitNumber    = 0;
  638.     SerialConfig -> StripBit8    = FALSE;
  639.     SerialConfig -> CheckCarrier    = FALSE;
  640.     SerialConfig -> xONxOFF        = FALSE;
  641.     SerialConfig -> PassThrough    = TRUE;
  642.     SerialConfig -> IgnoreCarrier    = FALSE;
  643.  
  644.     SerialConfig -> Quantum        = 256;
  645.  
  646.     SerialConfig -> UseNet        = FALSE;
  647.     SerialConfig -> NetID        = 0002;
  648.  
  649.     SerialConfig -> SatisfyODURequests = ODU_RELEASE;
  650.  
  651.     SerialConfig -> LastVersionSaved    = 0;
  652.     SerialConfig -> LastRevisionSaved    = 0;
  653. }
  654.  
  655. STATIC VOID
  656. ResetModem(struct ModemSettings *ModemConfig)
  657. {
  658.     strcpy(ModemConfig -> ModemInit,    "");
  659.     strcpy(ModemConfig -> ModemExit,    "");
  660.     strcpy(ModemConfig -> ModemHangup,    "~~~~~~~~+++~~~~~~ATH0\\r");
  661.     strcpy(ModemConfig -> DialPrefix,    "~~ATD\\w");
  662.     strcpy(ModemConfig -> DialSuffix,    "\\r");
  663.  
  664.     strcpy(ModemConfig -> NoCarrier,    "NO CARRIER");
  665.     strcpy(ModemConfig -> NoDialTone,    "NO DIALTONE");
  666.     strcpy(ModemConfig -> Connect,        "CONNECT");
  667.     strcpy(ModemConfig -> Voice,        "VOICE");
  668.     strcpy(ModemConfig -> Ring,        "RING");
  669.     strcpy(ModemConfig -> Busy,        "BUSY");
  670.     strcpy(ModemConfig -> Ok,        "OK");
  671.     strcpy(ModemConfig -> Error,        "ERROR");
  672.  
  673.     ModemConfig -> RedialDelay        = 20;
  674.     ModemConfig -> DialRetries        = 10;
  675.     ModemConfig -> DialTimeout        = 60;
  676.     ModemConfig -> ConnectAutoBaud        = FALSE;
  677.     ModemConfig -> DropDTR            = FALSE;
  678.     ModemConfig -> RedialAfterHangup    = FALSE;
  679.  
  680.     ModemConfig -> NoCarrierIsBusy        = TRUE;
  681.  
  682.     ModemConfig -> ConnectLimit        = 0;
  683.     ModemConfig -> ConnectLimitMacro[0]    = 0;
  684.  
  685.     ModemConfig -> TimeToConnect        = 0;
  686.  
  687.     ModemConfig -> VerboseDialing        = FALSE;
  688.  
  689.     ModemConfig -> DialMode            = DIALMODE_TONE;
  690.     ModemConfig -> Pad            = 0;
  691. }
  692.  
  693. STATIC VOID
  694. ResetScreen(struct ScreenSettings *ScreenConfig)
  695. {
  696.     ULONG         DisplayID;
  697.     struct Screen    *PubScreen;
  698.  
  699.     if(PubScreen = LockPubScreen(NULL))
  700.     {
  701.         DisplayID = GetVPModeID(&PubScreen -> ViewPort);
  702.  
  703.         UnlockPubScreen(NULL,PubScreen);
  704.     }
  705.     else
  706.         DisplayID = DEFAULT_MONITOR_ID | HIRESLACE_KEY;
  707.  
  708.     memset(ScreenConfig,0,sizeof(struct ScreenSettings));
  709.  
  710.     ScreenConfig -> DisplayMode        = DisplayID;
  711.     ScreenConfig -> ColourMode        = COLOUR_AMIGA;
  712.     ScreenConfig -> MakeScreenPublic    = TRUE;
  713.     ScreenConfig -> ShanghaiWindows        = FALSE;
  714.     ScreenConfig -> TitleBar        = TRUE;
  715.     ScreenConfig -> StatusLine        = STATUSLINE_STANDARD;
  716.     ScreenConfig -> Blinking        = TRUE;
  717.     ScreenConfig -> FasterLayout        = TRUE;
  718.     ScreenConfig -> UseWorkbench        = FALSE;
  719.  
  720.     strcpy(ScreenConfig -> FontName,"topaz.font");
  721.     ScreenConfig -> FontHeight = 8;
  722.  
  723.     ScreenConfig -> PubScreenName[0]    = 0;
  724.     ScreenConfig -> TimeMode        = ONLINETIME_BOTH;
  725.     ScreenConfig -> UsePens            = TRUE;
  726.     ScreenConfig -> PenColourMode        = COLOUR_AMIGA;
  727.  
  728.     ScreenConfig -> DisplayWidth        = 0;
  729.     ScreenConfig -> DisplayHeight        = 0;
  730.     ScreenConfig -> OverscanType        = OSCAN_TEXT;
  731.  
  732.     ScreenConfig -> ShareScreen        = FALSE;
  733.     ScreenConfig -> SplitStatus        = FALSE;
  734.  
  735.     ScreenConfig -> UseColours96        = FALSE;
  736. }
  737.  
  738. STATIC VOID
  739. ResetTerminal(struct TerminalSettings *TerminalConfig)
  740. {
  741.     TerminalConfig -> BellMode        = BELL_AUDIBLE;
  742.     TerminalConfig -> AlertMode        = ALERT_BEEP_SCREEN;
  743.     TerminalConfig -> EmulationMode        = EMULATION_ANSIVT100;
  744.     TerminalConfig -> FontMode        = FONT_STANDARD;
  745.  
  746.     TerminalConfig -> SendCR        = EOL_CR;
  747.     TerminalConfig -> SendLF        = EOL_LF;
  748.     TerminalConfig -> ReceiveCR        = EOL_CR;
  749.     TerminalConfig -> ReceiveLF        = EOL_LF;
  750.  
  751.     TerminalConfig -> NumColumns        = 0;
  752.     TerminalConfig -> NumLines        = 0;
  753.  
  754.     TerminalConfig -> KeyMapFileName[0]    = 0;
  755.     TerminalConfig -> EmulationFileName[0]    = 0;
  756.     TerminalConfig -> BeepFileName[0]    = 0;
  757.  
  758.     strcpy(TerminalConfig -> TextFontName,"topaz.font");
  759.     TerminalConfig -> TextFontHeight = 8;
  760.  
  761.     TerminalConfig -> UseTerminalTask = FALSE;
  762.     TerminalConfig -> Pad = 0;
  763.  
  764.     strcpy(TerminalConfig -> IBMFontName,"IBM.font");
  765.     TerminalConfig -> IBMFontHeight = 8;
  766. }
  767.  
  768. STATIC VOID
  769. ResetEmulation(struct EmulationSettings *EmulationConfig)
  770. {
  771.     WORD i;
  772.  
  773.     EmulationConfig -> CursorMode        = KEYMODE_STANDARD;
  774.     EmulationConfig -> NumericMode        = KEYMODE_STANDARD;
  775.  
  776.     EmulationConfig -> NewLineMode        = FALSE;
  777.     EmulationConfig -> InsertMode        = FALSE;
  778.  
  779.     EmulationConfig -> LineWrap        = TRUE;
  780.     EmulationConfig -> CursorWrap        = FALSE;
  781.  
  782.     EmulationConfig -> FontScale        = SCALE_NORMAL;
  783.     EmulationConfig -> ScrollMode        = SCROLL_JUMP;
  784.     EmulationConfig -> DestructiveBackspace    = FALSE;
  785.     EmulationConfig -> SwapBSDelete        = FALSE;
  786.     EmulationConfig -> PrinterEnabled    = TRUE;
  787.     EmulationConfig -> AnswerBack[0]    = 0;
  788.     EmulationConfig -> CLSResetsCursor    = 0;
  789.  
  790.     EmulationConfig -> KeysLocked        = FALSE;
  791.     EmulationConfig -> MaxScroll        = 0;
  792.     EmulationConfig -> MaxJump        = 1;
  793.     EmulationConfig -> CursorLocked        = FALSE;
  794.     EmulationConfig -> FontLocked        = FALSE;
  795.     EmulationConfig -> LockWrapping        = FALSE;
  796.     EmulationConfig -> LockStyle        = FALSE;
  797.     EmulationConfig -> LockColour        = FALSE;
  798.  
  799.     EmulationConfig -> UseStandardPens    = TRUE;
  800.  
  801.     for(i = TEXTATTR_UNDERLINE ; i <= TEXTATTR_INVERSE ; i++)
  802.         EmulationConfig -> Attributes[i] = i;
  803.  
  804.     for(i = 0 ; i < 16 ; i++)
  805.         EmulationConfig -> Pens[i] = i;
  806. }
  807.  
  808. STATIC VOID
  809. ResetClip(struct ClipSettings *ClipConfig)
  810. {
  811.     ClipConfig -> ClipboardUnit    = 0;
  812.     ClipConfig -> LineDelay        = 0;
  813.     ClipConfig -> CharDelay        = 0;
  814.  
  815.     ClipConfig -> InsertPrefix[0] = 0;
  816.     strcpy(ClipConfig -> InsertSuffix,"\\r");
  817.  
  818.     ClipConfig -> LinePrompt[0]    = 0;
  819.     ClipConfig -> SendTimeout    = 0;
  820.     ClipConfig -> PacingMode    = PACE_DIRECT;
  821.     ClipConfig -> ConvertLF        = TRUE;
  822. }
  823.  
  824. STATIC VOID
  825. ResetCapture(struct CaptureSettings *CaptureConfig)
  826. {
  827.     CaptureConfig -> LogActions        = FALSE;
  828.     CaptureConfig -> LogCall        = FALSE;
  829.     CaptureConfig -> LogFileName[0]        = 0;
  830.  
  831.     CaptureConfig -> MaxBufferSize        = 0;
  832.     CaptureConfig -> BufferEnabled        = TRUE;
  833.  
  834.     CaptureConfig -> ConnectAutoCapture    = FALSE;
  835.     CaptureConfig -> CaptureFilterMode    = FILTER_BOTH;
  836.     CaptureConfig -> CapturePath[0]        = 0;
  837.  
  838.     CaptureConfig -> CallLogFileName[0]    = 0;
  839.     CaptureConfig -> BufferPath[0]        = 0;
  840.  
  841.     CaptureConfig -> AutoCaptureDate    = AUTOCAPTURE_DATE_NAME;
  842.     CaptureConfig -> SearchHistory        = 10;
  843.  
  844.     CaptureConfig -> OpenBufferWindow    = BUFFER_END;
  845.     CaptureConfig -> OpenBufferScreen    = BUFFER_TOP;
  846.     CaptureConfig -> BufferScreenPosition    = SCREEN_CENTRE;
  847.     CaptureConfig -> BufferWidth        = 80;
  848.  
  849.     CaptureConfig -> RememberBufferWindow    = FALSE;
  850.     CaptureConfig -> RememberBufferScreen    = FALSE;
  851.  
  852.     CaptureConfig -> BufferScreenMode    = INVALID_ID;
  853.  
  854.     CaptureConfig -> ConvertChars        = FALSE;
  855.     CaptureConfig -> Pad            = 0;
  856. }
  857.  
  858. STATIC VOID
  859. ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer)
  860. {
  861.     if(!PathBuffer)
  862.         PathBuffer = "TERM:config";
  863.  
  864.     strcpy(FileConfig -> ProtocolFileName,"xprzmodem.library");
  865.  
  866.     if(!LastTranslation[0])
  867.     {
  868.         strcpy(LastTranslation,PathBuffer);
  869.  
  870.         AddPart(LastTranslation,"translation.prefs",MAX_FILENAME_LENGTH);
  871.     }
  872.  
  873.     strcpy(FileConfig -> TranslationFileName,LastTranslation);
  874.  
  875.     if(!LastMacros[0])
  876.     {
  877.         strcpy(LastMacros,PathBuffer);
  878.  
  879.         AddPart(LastMacros,"functionkeys.prefs",MAX_FILENAME_LENGTH);
  880.     }
  881.  
  882.     strcpy(FileConfig -> MacroFileName,LastMacros);
  883.  
  884.     if(!LastFastMacros[0])
  885.     {
  886.         strcpy(LastFastMacros,PathBuffer);
  887.  
  888.         AddPart(LastFastMacros,"fastmacros.prefs",MAX_FILENAME_LENGTH);
  889.     }
  890.  
  891.     strcpy(FileConfig -> FastMacroFileName,LastFastMacros);
  892.  
  893.     if(!LastCursorKeys[0])
  894.     {
  895.         strcpy(LastCursorKeys,PathBuffer);
  896.  
  897.         AddPart(LastCursorKeys,"cursorkeys.prefs",MAX_FILENAME_LENGTH);
  898.     }
  899.  
  900.     strcpy(FileConfig -> CursorFileName,LastCursorKeys);
  901. }
  902.  
  903. STATIC VOID
  904. ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer)
  905. {
  906.     if(!PathBuffer)
  907.         PathBuffer = "TERM:config";
  908.  
  909.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  910.  
  911.     PathConfig -> ASCIIUploadPath[0]    = 0;
  912.     PathConfig -> ASCIIDownloadPath[0]    = 0;
  913.     PathConfig -> TextUploadPath[0]        = 0;
  914.     PathConfig -> TextDownloadPath[0]    = 0;
  915.     PathConfig -> BinaryUploadPath[0]    = 0;
  916.     PathConfig -> BinaryDownloadPath[0]    = 0;
  917.  
  918.     strcpy(PathConfig -> HelpFile,"PROGDIR:term.guide");
  919.  
  920.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  921.  
  922.     GetEnvDOS(PathConfig -> Editor,"EDITOR");
  923. }
  924.  
  925. STATIC VOID
  926. ResetMisc(struct MiscSettings *MiscConfig)
  927. {
  928.     MiscConfig -> Priority            = 1;
  929.     MiscConfig -> BackupConfig        = FALSE;
  930.  
  931.     MiscConfig -> OpenFastMacroPanel    = FALSE;
  932.     MiscConfig -> ReleaseDevice        = TRUE;
  933.  
  934.     MiscConfig -> TransferServer        = TRUE;
  935.     MiscConfig -> EmulationServer        = TRUE;
  936.  
  937.     MiscConfig -> OverridePath        = TRUE;
  938.     MiscConfig -> AutoUpload        = TRUE;
  939.     MiscConfig -> SetArchivedBit        = FALSE;
  940.     MiscConfig -> IdentifyFiles        = IDENTIFY_FILETYPE;
  941.     MiscConfig -> TransferIcons        = FALSE;
  942.     MiscConfig -> CreateIcons        = FALSE;
  943.     MiscConfig -> SimpleIO            = FALSE;
  944.     MiscConfig -> PerfMeter            = FALSE;
  945.  
  946.     MiscConfig -> IOBufferSize        = 32768;
  947.     MiscConfig -> HideUploadIcon        = FALSE;
  948.  
  949.     MiscConfig -> ProtectiveMode        = TRUE;
  950. }
  951.  
  952. STATIC VOID
  953. ResetCommand(struct CommandSettings *CommandConfig)
  954. {
  955.     CommandConfig -> StartupMacro[0]    = 0;
  956.     CommandConfig -> LogoffMacro[0]        = 0;
  957.     CommandConfig -> LoginMacro[0]        = 0;
  958.     CommandConfig -> UploadMacro[0]        = 0;
  959.     CommandConfig -> DownloadMacro[0]    = 0;
  960. }
  961.  
  962. STATIC VOID
  963. ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib)
  964. {
  965.     WORD i;
  966.  
  967.     if(!DefaultLib)
  968.         strcpy(TransferConfig -> DefaultLibrary,"xprzmodem.library");
  969.     else
  970.         strcpy(TransferConfig -> DefaultLibrary,DefaultLib);
  971.  
  972.     for(i = 0 ; i < strlen(TransferConfig -> DefaultLibrary) - 6 ; i++)
  973.     {
  974.         if(!Strnicmp(&TransferConfig -> DefaultLibrary[i],"zmodem",6))
  975.         {
  976.             strcpy(TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature,"*\030B01");
  977.  
  978.             TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Length = strlen(TransferConfig -> Signatures[TRANSFERSIG_DEFAULTUPLOAD] . Signature);
  979.  
  980.             break;
  981.         }
  982.     }
  983.  
  984.     strcpy(TransferConfig -> ASCIIUploadLibrary,    "xprascii.library");
  985.     strcpy(TransferConfig -> ASCIIDownloadLibrary,    "xprascii.library");
  986.  
  987.     TransferConfig -> TextUploadLibrary[0]        = 0;
  988.     TransferConfig -> TextDownloadLibrary[0]    = 0;
  989.  
  990.     TransferConfig -> BinaryUploadLibrary[0]    = 0;
  991.     TransferConfig -> BinaryDownloadLibrary[0]    = 0;
  992.  
  993.     TransferConfig -> InternalASCIIUpload        = FALSE;
  994.     TransferConfig -> InternalASCIIDownload        = FALSE;
  995.     TransferConfig -> QuietTransfer            = FALSE;
  996.     TransferConfig -> MangleFileNames        = FALSE;
  997.  
  998.     TransferConfig -> LinePrompt[0]            = 0;
  999.     TransferConfig -> SendTimeout            = 0;
  1000.     TransferConfig -> PacingMode            = PACE_DIRECT;
  1001.     TransferConfig -> StripBit8            = FALSE;
  1002.     TransferConfig -> IgnoreDataPastArnold        = TRUE;
  1003.     TransferConfig -> TerminatorChar        = 0x1A;
  1004.     TransferConfig -> SendCR            = EOL_CR;
  1005.     TransferConfig -> SendLF            = EOL_LF;
  1006.     TransferConfig -> ReceiveCR            = EOL_CR;
  1007.     TransferConfig -> ReceiveLF            = EOL_LF;
  1008.  
  1009.     TransferConfig -> ErrorNotification        = 20;
  1010.     TransferConfig -> TransferNotification        = XFERNOTIFY_ALWAYS;
  1011.  
  1012.     TransferConfig -> DefaultType            = XFER_XPR;
  1013.     TransferConfig -> ASCIIDownloadType        = XFER_XPR;
  1014.     TransferConfig -> ASCIIUploadType        = XFER_XPR;
  1015.     TransferConfig -> TextDownloadType        = XFER_DEFAULT;
  1016.     TransferConfig -> TextUploadType        = XFER_DEFAULT;
  1017.     TransferConfig -> BinaryDownloadType        = XFER_DEFAULT;
  1018.     TransferConfig -> BinaryUploadType        = XFER_DEFAULT;
  1019.  
  1020.     memset(TransferConfig -> Signatures,0,sizeof(TransferConfig -> Signatures));
  1021.  
  1022.     TransferConfig -> OverridePath            = TRUE;
  1023.     TransferConfig -> SetArchivedBit        = FALSE;
  1024.     TransferConfig -> IdentifyFiles            = IDENTIFY_FILETYPE;
  1025.     TransferConfig -> TransferIcons            = FALSE;
  1026.     TransferConfig -> PerfMeter            = FALSE;
  1027.     TransferConfig -> HideUploadIcon        = FALSE;
  1028. }
  1029.  
  1030.     /* ResetConfig():
  1031.      *
  1032.      *    Initialize configuration with default values.
  1033.      */
  1034.  
  1035. VOID __regargs
  1036. ResetConfig(struct Configuration *Config,STRPTR PathBuffer)
  1037. {
  1038.     if(!PathBuffer)
  1039.         PathBuffer = "TERM:config";
  1040.  
  1041.     ResetPath(Config -> PathConfig,PathBuffer);
  1042.     ResetFile(Config -> FileConfig,PathBuffer);
  1043.  
  1044.     ResetSerialConfig(Config -> SerialConfig);
  1045.     ResetModem(Config -> ModemConfig);
  1046.     ResetScreen(Config -> ScreenConfig);
  1047.     ResetTerminal(Config -> TerminalConfig);
  1048.     ResetEmulation(Config -> EmulationConfig);
  1049.     ResetClip(Config -> ClipConfig);
  1050.     ResetCapture(Config -> CaptureConfig);
  1051.     ResetMisc(Config -> MiscConfig);
  1052.     ResetCommand(Config -> CommandConfig);
  1053.     ResetTransfer(Config -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  1054. }
  1055.  
  1056. VOID __regargs
  1057. DeleteConfigEntry(struct Configuration *Config,BYTE Type)
  1058. {
  1059.     if(Type == PREF_ALL)
  1060.     {
  1061.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1062.             DeleteConfigEntry(Config,Type);
  1063.     }
  1064.     else
  1065.     {
  1066.         switch(Type)
  1067.         {
  1068.             case PREF_SERIAL:
  1069.  
  1070.                 if(Config -> SerialConfig)
  1071.                 {
  1072.                     FreeVecPooled(Config -> SerialConfig);
  1073.  
  1074.                     Config -> SerialConfig = NULL;
  1075.                 }
  1076.  
  1077.                 break;
  1078.  
  1079.             case PREF_MODEM:
  1080.  
  1081.                 if(Config -> ModemConfig)
  1082.                 {
  1083.                     FreeVecPooled(Config -> ModemConfig);
  1084.  
  1085.                     Config -> ModemConfig = NULL;
  1086.                 }
  1087.  
  1088.                 break;
  1089.  
  1090.             case PREF_COMMAND:
  1091.  
  1092.                 if(Config -> CommandConfig)
  1093.                 {
  1094.                     FreeVecPooled(Config -> CommandConfig);
  1095.  
  1096.                     Config -> CommandConfig = NULL;
  1097.                 }
  1098.  
  1099.                 break;
  1100.  
  1101.             case PREF_SCREEN:
  1102.  
  1103.                 if(Config -> ScreenConfig)
  1104.                 {
  1105.                     FreeVecPooled(Config -> ScreenConfig);
  1106.  
  1107.                     Config -> ScreenConfig = NULL;
  1108.                 }
  1109.  
  1110.                 break;
  1111.  
  1112.             case PREF_TERMINAL:
  1113.  
  1114.                 if(Config -> TerminalConfig)
  1115.                 {
  1116.                     FreeVecPooled(Config -> TerminalConfig);
  1117.  
  1118.                     Config -> TerminalConfig = NULL;
  1119.                 }
  1120.  
  1121.                 break;
  1122.  
  1123.             case PREF_PATH:
  1124.  
  1125.                 if(Config -> PathConfig)
  1126.                 {
  1127.                     FreeVecPooled(Config -> PathConfig);
  1128.  
  1129.                     Config -> PathConfig = NULL;
  1130.                 }
  1131.  
  1132.                 break;
  1133.  
  1134.             case PREF_MISC:
  1135.  
  1136.                 if(Config -> MiscConfig)
  1137.                 {
  1138.                     FreeVecPooled(Config -> MiscConfig);
  1139.  
  1140.                     Config -> MiscConfig = NULL;
  1141.                 }
  1142.  
  1143.                 break;
  1144.  
  1145.             case PREF_CLIP:
  1146.  
  1147.                 if(Config -> ClipConfig)
  1148.                 {
  1149.                     FreeVecPooled(Config -> ClipConfig);
  1150.  
  1151.                     Config -> ClipConfig = NULL;
  1152.                 }
  1153.  
  1154.                 break;
  1155.  
  1156.             case PREF_CAPTURE:
  1157.  
  1158.                 if(Config -> CaptureConfig)
  1159.                 {
  1160.                     FreeVecPooled(Config -> CaptureConfig);
  1161.  
  1162.                     Config -> CaptureConfig = NULL;
  1163.                 }
  1164.  
  1165.                 break;
  1166.  
  1167.             case PREF_FILE:
  1168.  
  1169.                 if(Config -> FileConfig)
  1170.                 {
  1171.                     FreeVecPooled(Config -> FileConfig);
  1172.  
  1173.                     Config -> FileConfig = NULL;
  1174.                 }
  1175.  
  1176.                 break;
  1177.  
  1178.             case PREF_EMULATION:
  1179.  
  1180.                 if(Config -> EmulationConfig)
  1181.                 {
  1182.                     FreeVecPooled(Config -> EmulationConfig);
  1183.  
  1184.                     Config -> EmulationConfig = NULL;
  1185.                 }
  1186.  
  1187.                 break;
  1188.  
  1189.             case PREF_TRANSFER:
  1190.  
  1191.                 if(Config -> TransferConfig)
  1192.                 {
  1193.                     FreeVecPooled(Config -> TransferConfig);
  1194.  
  1195.                     Config -> TransferConfig = NULL;
  1196.                 }
  1197.  
  1198.                 break;
  1199.         }
  1200.     }
  1201. }
  1202.  
  1203. VOID __regargs
  1204. ResetConfigEntry(struct Configuration *Configuration,BYTE Type,BYTE Default)
  1205. {
  1206.     if(Type == PREF_ALL)
  1207.     {
  1208.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1209.             ResetConfigEntry(Configuration,Type,Default);
  1210.     }
  1211.     else
  1212.     {
  1213.         switch(Type)
  1214.         {
  1215.             case PREF_SERIAL:
  1216.  
  1217.                 if(Default || !Config -> SerialConfig)
  1218.                     ResetSerialConfig(Configuration -> SerialConfig);
  1219.                 else
  1220.                     memcpy(Configuration -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  1221.  
  1222.                 break;
  1223.  
  1224.             case PREF_MODEM:
  1225.  
  1226.                 if(Default || !Config -> ModemConfig)
  1227.                     ResetModem(Configuration -> ModemConfig);
  1228.                 else
  1229.                     memcpy(Configuration -> ModemConfig,Config -> ModemConfig,sizeof(struct ModemSettings));
  1230.  
  1231.                 break;
  1232.  
  1233.             case PREF_COMMAND:
  1234.  
  1235.                 if(Default || !Config -> CommandConfig)
  1236.                     ResetCommand(Configuration -> CommandConfig);
  1237.                 else
  1238.                     memcpy(Configuration -> CommandConfig,Config -> CommandConfig,sizeof(struct CommandSettings));
  1239.  
  1240.                 break;
  1241.  
  1242.             case PREF_SCREEN:
  1243.  
  1244.                 if(Default || !Config -> ScreenConfig)
  1245.                     ResetScreen(Configuration -> ScreenConfig);
  1246.                 else
  1247.                     memcpy(Configuration -> ScreenConfig,Config -> ScreenConfig,sizeof(struct ScreenSettings));
  1248.  
  1249.                 FixScreenPens(Configuration -> ScreenConfig);
  1250.  
  1251.                 break;
  1252.  
  1253.             case PREF_TERMINAL:
  1254.  
  1255.                 if(Default || !Config -> TerminalConfig)
  1256.                     ResetTerminal(Configuration -> TerminalConfig);
  1257.                 else
  1258.                     memcpy(Configuration -> TerminalConfig,Config -> TerminalConfig,sizeof(struct TerminalSettings));
  1259.  
  1260.                 break;
  1261.  
  1262.             case PREF_PATH:
  1263.  
  1264.                 if(Default || !Config -> PathConfig)
  1265.                     ResetPath(Configuration -> PathConfig,NULL);
  1266.                 else
  1267.                     memcpy(Configuration -> PathConfig,Config -> PathConfig,sizeof(struct PathSettings));
  1268.  
  1269.                 break;
  1270.  
  1271.             case PREF_MISC:
  1272.  
  1273.                 if(Default || !Config -> MiscConfig)
  1274.                     ResetMisc(Configuration -> MiscConfig);
  1275.                 else
  1276.                     memcpy(Configuration -> MiscConfig,Config -> MiscConfig,sizeof(struct MiscSettings));
  1277.  
  1278.                 break;
  1279.  
  1280.             case PREF_CLIP:
  1281.  
  1282.                 if(Default || !Config -> ClipConfig)
  1283.                     ResetClip(Configuration -> ClipConfig);
  1284.                 else
  1285.                     memcpy(Configuration -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings));
  1286.  
  1287.                 break;
  1288.  
  1289.             case PREF_CAPTURE:
  1290.  
  1291.                 if(Default || !Config -> CaptureConfig)
  1292.                     ResetCapture(Configuration -> CaptureConfig);
  1293.                 else
  1294.                     memcpy(Configuration -> CaptureConfig,Config -> CaptureConfig,sizeof(struct CaptureSettings));
  1295.  
  1296.                 break;
  1297.  
  1298.             case PREF_FILE:
  1299.  
  1300.                 if(Default || !Config -> FileConfig)
  1301.                     ResetFile(Configuration -> FileConfig,NULL);
  1302.                 else
  1303.                     memcpy(Configuration -> FileConfig,Config -> FileConfig,sizeof(struct FileSettings));
  1304.  
  1305.                 break;
  1306.  
  1307.             case PREF_EMULATION:
  1308.  
  1309.                 if(Default || !Config -> EmulationConfig)
  1310.                     ResetEmulation(Configuration -> EmulationConfig);
  1311.                 else
  1312.                     memcpy(Configuration -> EmulationConfig,Config -> EmulationConfig,sizeof(struct EmulationSettings));
  1313.  
  1314.                 break;
  1315.  
  1316.             case PREF_TRANSFER:
  1317.  
  1318.                 if(Default || !Config -> TransferConfig)
  1319.                     ResetTransfer(Configuration -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  1320.                 else
  1321.                     memcpy(Configuration -> TransferConfig,Config -> TransferConfig,sizeof(struct TransferSettings));
  1322.  
  1323.                 break;
  1324.         }
  1325.     }
  1326. }
  1327.  
  1328. APTR __regargs
  1329. GetConfigEntry(struct Configuration *Config,BYTE Type)
  1330. {
  1331.     switch(Type)
  1332.     {
  1333.         case PREF_SERIAL:
  1334.  
  1335.             return(Config -> SerialConfig);
  1336.  
  1337.         case PREF_MODEM:
  1338.  
  1339.             return(Config -> ModemConfig);
  1340.  
  1341.         case PREF_COMMAND:
  1342.  
  1343.             return(Config -> CommandConfig);
  1344.  
  1345.         case PREF_SCREEN:
  1346.  
  1347.             return(Config -> ScreenConfig);
  1348.  
  1349.         case PREF_TERMINAL:
  1350.  
  1351.             return(Config -> TerminalConfig);
  1352.  
  1353.         case PREF_PATH:
  1354.  
  1355.             return(Config -> PathConfig);
  1356.  
  1357.         case PREF_MISC:
  1358.  
  1359.             return(Config -> MiscConfig);
  1360.  
  1361.         case PREF_CLIP:
  1362.  
  1363.             return(Config -> ClipConfig);
  1364.  
  1365.         case PREF_CAPTURE:
  1366.  
  1367.             return(Config -> CaptureConfig);
  1368.  
  1369.         case PREF_FILE:
  1370.  
  1371.             return(Config -> FileConfig);
  1372.  
  1373.         case PREF_EMULATION:
  1374.  
  1375.             return(Config -> EmulationConfig);
  1376.  
  1377.         case PREF_TRANSFER:
  1378.  
  1379.             return(Config -> TransferConfig);
  1380.  
  1381.         default:
  1382.  
  1383.             return(NULL);
  1384.     }
  1385. }
  1386.  
  1387. BYTE __regargs
  1388. CreateConfigEntry(struct Configuration *Config,BYTE Type)
  1389. {
  1390.     if(Type == PREF_ALL)
  1391.     {
  1392.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1393.         {
  1394.             if(!CreateConfigEntry(Config,Type))
  1395.             {
  1396.                 DeleteConfigEntry(Config,PREF_ALL);
  1397.  
  1398.                 return(FALSE);
  1399.             }
  1400.         }
  1401.  
  1402.         return(TRUE);
  1403.     }
  1404.     else
  1405.     {
  1406.         APTR Data;
  1407.  
  1408.         switch(Type)
  1409.         {
  1410.             case PREF_SERIAL:
  1411.  
  1412.                 Data = Config -> SerialConfig;
  1413.                 break;
  1414.  
  1415.             case PREF_MODEM:
  1416.  
  1417.                 Data = Config -> ModemConfig;
  1418.                 break;
  1419.  
  1420.             case PREF_COMMAND:
  1421.  
  1422.                 Data = Config -> CommandConfig;
  1423.                 break;
  1424.  
  1425.             case PREF_SCREEN:
  1426.  
  1427.                 Data = Config -> ScreenConfig;
  1428.                 break;
  1429.  
  1430.             case PREF_TERMINAL:
  1431.  
  1432.                 Data = Config -> TerminalConfig;
  1433.                 break;
  1434.  
  1435.             case PREF_PATH:
  1436.  
  1437.                 Data = Config -> PathConfig;
  1438.                 break;
  1439.  
  1440.             case PREF_MISC:
  1441.  
  1442.                 Data = Config -> MiscConfig;
  1443.                 break;
  1444.  
  1445.             case PREF_CLIP:
  1446.  
  1447.                 Data = Config -> ClipConfig;
  1448.                 break;
  1449.  
  1450.             case PREF_CAPTURE:
  1451.  
  1452.                 Data = Config -> CaptureConfig;
  1453.                 break;
  1454.  
  1455.             case PREF_FILE:
  1456.  
  1457.                 Data = Config -> FileConfig;
  1458.                 break;
  1459.  
  1460.             case PREF_EMULATION:
  1461.  
  1462.                 Data = Config -> EmulationConfig;
  1463.                 break;
  1464.  
  1465.             case PREF_TRANSFER:
  1466.  
  1467.                 Data = Config -> TransferConfig;
  1468.                 break;
  1469.  
  1470.             default:
  1471.  
  1472.                 return(FALSE);
  1473.         }
  1474.  
  1475.         if(!Data)
  1476.         {
  1477.             if(Data = AllocVecPooled(SizeTable[Type - 1],MEMF_ANY | MEMF_CLEAR))
  1478.             {
  1479.                 (*ResetTable[Type - 1])(Data,NULL);
  1480.  
  1481.                 switch(Type)
  1482.                 {
  1483.                     case PREF_SERIAL:
  1484.  
  1485.                         Config -> SerialConfig        = Data;
  1486.                         break;
  1487.  
  1488.                     case PREF_MODEM:
  1489.  
  1490.                         Config -> ModemConfig        = Data;
  1491.                         break;
  1492.  
  1493.                     case PREF_COMMAND:
  1494.  
  1495.                         Config -> CommandConfig        = Data;
  1496.                         break;
  1497.  
  1498.                     case PREF_SCREEN:
  1499.  
  1500.                         Config -> ScreenConfig        = Data;
  1501.                         break;
  1502.  
  1503.                     case PREF_TERMINAL:
  1504.  
  1505.                         Config -> TerminalConfig    = Data;
  1506.                         break;
  1507.  
  1508.                     case PREF_PATH:
  1509.  
  1510.                         Config -> PathConfig        = Data;
  1511.                         break;
  1512.  
  1513.                     case PREF_MISC:
  1514.  
  1515.                         Config -> MiscConfig        = Data;
  1516.                         break;
  1517.  
  1518.                     case PREF_CLIP:
  1519.  
  1520.                         Config -> ClipConfig        = Data;
  1521.                         break;
  1522.  
  1523.                     case PREF_CAPTURE:
  1524.  
  1525.                         Config -> CaptureConfig        = Data;
  1526.                         break;
  1527.  
  1528.                     case PREF_FILE:
  1529.  
  1530.                         Config -> FileConfig        = Data;
  1531.                         break;
  1532.  
  1533.                     case PREF_EMULATION:
  1534.  
  1535.                         Config -> EmulationConfig    = Data;
  1536.                         break;
  1537.  
  1538.                     case PREF_TRANSFER:
  1539.  
  1540.                         Config -> TransferConfig    = Data;
  1541.                         break;
  1542.                 }
  1543.  
  1544.                 return(TRUE);
  1545.             }
  1546.             else
  1547.                 return(FALSE);
  1548.         }
  1549.         else
  1550.             return(TRUE);
  1551.     }
  1552. }
  1553.  
  1554. VOID __regargs
  1555. DeleteConfiguration(struct Configuration *Config)
  1556. {
  1557.     if(Config)
  1558.     {
  1559.         DeleteConfigEntry(Config,PREF_ALL);
  1560.  
  1561.         FreeVecPooled(Config);
  1562.     }
  1563. }
  1564.  
  1565. struct Configuration * __regargs
  1566. CreateConfiguration(BYTE Fill)
  1567. {
  1568.     struct Configuration *Config;
  1569.  
  1570.     if(Config = (struct Configuration *)AllocVecPooled(sizeof(struct Configuration),MEMF_ANY | MEMF_CLEAR))
  1571.     {
  1572.         if(Fill)
  1573.         {
  1574.             if(!CreateConfigEntry(Config,PREF_ALL))
  1575.             {
  1576.                 FreeVecPooled(Config);
  1577.  
  1578.                 return(NULL);
  1579.             }
  1580.         }
  1581.  
  1582.         return(Config);
  1583.     }
  1584.     else
  1585.         return(NULL);
  1586. }
  1587.  
  1588. STATIC BYTE
  1589. WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password)
  1590. {
  1591.     APTR Data;
  1592.  
  1593.     switch(Type)
  1594.     {
  1595.         case PREF_SERIAL:
  1596.  
  1597.             Data = Config -> SerialConfig;
  1598.             break;
  1599.  
  1600.         case PREF_MODEM:
  1601.  
  1602.             Data = Config -> ModemConfig;
  1603.             break;
  1604.  
  1605.         case PREF_COMMAND:
  1606.  
  1607.             Data = Config -> CommandConfig;
  1608.             break;
  1609.  
  1610.         case PREF_SCREEN:
  1611.  
  1612.             Data = Config -> ScreenConfig;
  1613.             break;
  1614.  
  1615.         case PREF_TERMINAL:
  1616.  
  1617.             Data = Config -> TerminalConfig;
  1618.             break;
  1619.  
  1620.         case PREF_PATH:
  1621.  
  1622.             Data = Config -> PathConfig;
  1623.             break;
  1624.  
  1625.         case PREF_MISC:
  1626.  
  1627.             Data = Config -> MiscConfig;
  1628.             break;
  1629.  
  1630.         case PREF_CLIP:
  1631.  
  1632.             Data = Config -> ClipConfig;
  1633.             break;
  1634.  
  1635.         case PREF_CAPTURE:
  1636.  
  1637.             Data = Config -> CaptureConfig;
  1638.             break;
  1639.  
  1640.         case PREF_FILE:
  1641.  
  1642.             Data = Config -> FileConfig;
  1643.             break;
  1644.  
  1645.         case PREF_EMULATION:
  1646.  
  1647.             Data = Config -> EmulationConfig;
  1648.             break;
  1649.  
  1650.         case PREF_TRANSFER:
  1651.  
  1652.             Data = Config -> TransferConfig;
  1653.             break;
  1654.  
  1655.         default:
  1656.  
  1657.             Data = NULL;
  1658.             break;
  1659.     }
  1660.  
  1661.     if(Data)
  1662.     {
  1663.         if(TempBuffer)
  1664.         {
  1665.             Encrypt(Data,SizeTable[Type - 1],TempBuffer,Password,20);
  1666.  
  1667.             Data = TempBuffer;
  1668.         }
  1669.  
  1670.         if(!PushChunk(Handle,0,TypeTable[Type - 1],SizeTable[Type - 1]))
  1671.         {
  1672.             if(WriteChunkRecords(Handle,Data,SizeTable[Type - 1],1) == 1)
  1673.             {
  1674.                 if(!PopChunk(Handle))
  1675.                     return(TRUE);
  1676.             }
  1677.         }
  1678.  
  1679.         return(FALSE);
  1680.     }
  1681.     else
  1682.         return(TRUE);
  1683. }
  1684.  
  1685. STATIC UBYTE
  1686. IsConfigChunk(ULONG ID)
  1687. {
  1688.     UBYTE Type;
  1689.  
  1690.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1691.     {
  1692.         if(ID == TypeTable[Type - 1])
  1693.             return(Type);
  1694.     }
  1695.  
  1696.     return(0);
  1697. }
  1698.  
  1699. STATIC BYTE
  1700. WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password)
  1701. {
  1702.     UBYTE Type;
  1703.  
  1704.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1705.     {
  1706.         if(!WriteConfigChunk(Handle,Config,Type,TempBuffer,Password))
  1707.             return(FALSE);
  1708.     }
  1709.  
  1710.     return(TRUE);
  1711. }
  1712.  
  1713. VOID __regargs
  1714. SaveConfig(struct Configuration *Src,struct Configuration *Dst)
  1715. {
  1716.     if(Dst -> SerialConfig && Src -> SerialConfig)
  1717.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1718.  
  1719.     if(Dst -> ModemConfig && Src -> ModemConfig)
  1720.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1721.  
  1722.     if(Dst -> ScreenConfig && Src -> ScreenConfig)
  1723.     {
  1724.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1725.  
  1726.         FixScreenPens(Dst -> ScreenConfig);
  1727.     }
  1728.  
  1729.     if(Dst -> TerminalConfig && Src -> TerminalConfig)
  1730.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1731.  
  1732.     if(Dst -> EmulationConfig && Src -> EmulationConfig)
  1733.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1734.  
  1735.     if(Dst -> ClipConfig && Src -> ClipConfig)
  1736.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1737.  
  1738.     if(Dst -> CaptureConfig && Src -> CaptureConfig)
  1739.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1740.  
  1741.     if(Dst -> CommandConfig && Src -> CommandConfig)
  1742.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1743.  
  1744.     if(Dst -> MiscConfig && Src -> MiscConfig)
  1745.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1746.  
  1747.     if(Dst -> PathConfig && Src -> PathConfig)
  1748.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1749.  
  1750.     if(Dst -> FileConfig && Src -> FileConfig)
  1751.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1752.  
  1753.     if(Dst -> TransferConfig && Src -> TransferConfig)
  1754.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1755. }
  1756.  
  1757. VOID __regargs
  1758. UpdateConfig(struct Configuration *Src,struct Configuration *Dst)
  1759. {
  1760.     if(Src -> SerialConfig)
  1761.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1762.  
  1763.     if(Src -> ModemConfig)
  1764.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1765.  
  1766.     if(Src -> ScreenConfig)
  1767.     {
  1768.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1769.  
  1770.         FixScreenPens(Dst -> ScreenConfig);
  1771.     }
  1772.  
  1773.     if(Src -> TerminalConfig)
  1774.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1775.  
  1776.     if(Src -> EmulationConfig)
  1777.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1778.  
  1779.     if(Src -> ClipConfig)
  1780.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1781.  
  1782.     if(Src -> CaptureConfig)
  1783.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1784.  
  1785.     if(Src -> CommandConfig)
  1786.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1787.  
  1788.     if(Src -> MiscConfig)
  1789.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1790.  
  1791.     if(Src -> PathConfig)
  1792.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1793.  
  1794.     if(Src -> FileConfig)
  1795.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1796.  
  1797.     if(Src -> TransferConfig)
  1798.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1799. }
  1800.  
  1801. VOID __regargs
  1802. SwapConfig(struct Configuration *Src,struct Configuration *Dst)
  1803. {
  1804.     swmem(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1805.     swmem(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1806.     swmem(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1807.     swmem(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1808.     swmem(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1809.     swmem(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1810.     swmem(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1811.     swmem(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1812.     swmem(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1813.     swmem(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1814.     swmem(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1815.     swmem(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1816. }
  1817.  
  1818.     /* SavePhonebook(STRPTR Name):
  1819.      *
  1820.      *    Save the current phone book to a disk file.
  1821.      */
  1822.  
  1823. BYTE __regargs
  1824. SavePhonebook(STRPTR Name)
  1825. {
  1826.     struct IFFHandle    *Handle;
  1827.     BYTE             Success = FALSE;
  1828.     LONG             Error = 0;
  1829.  
  1830.     if(Phonebook && NumPhoneEntries)
  1831.     {
  1832.         if(Handle = (struct IFFHandle *)AllocIFF())
  1833.         {
  1834.             if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  1835.             {
  1836.                 InitIFFasDOS(Handle);
  1837.  
  1838.                 if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  1839.                 {
  1840.                     if(!(Error = PushChunk(Handle,ID_TERM,ID_CAT,IFFSIZE_UNKNOWN)))
  1841.                     {
  1842.                         if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1843.                         {
  1844.                             if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  1845.                             {
  1846.                                 struct TermInfo TermInfo;
  1847.  
  1848.                                 TermInfo . Version    = CONFIG_FILE_VERSION;
  1849.                                 TermInfo . Revision    = CONFIG_FILE_REVISION;
  1850.  
  1851.                                 if(WriteChunkRecords(Handle,&TermInfo,sizeof(struct TermInfo),1) == 1)
  1852.                                 {
  1853.                                     if(!(Error = PopChunk(Handle)))
  1854.                                     {
  1855.                                         STRPTR TempBuffer = NULL;
  1856.  
  1857.                                         if(PhonePasswordUsed)
  1858.                                         {
  1859.                                             if(!(Error = PushChunk(Handle,0,ID_PSWD,20)))
  1860.                                             {
  1861.                                                 Success = TRUE;
  1862.  
  1863.                                                 if(WriteChunkBytes(Handle,PhonePassword,20) != 20)
  1864.                                                     Success = FALSE;
  1865.  
  1866.                                                 if(PopChunk(Handle))
  1867.                                                     Success = FALSE;
  1868.  
  1869.                                                 if(Success)
  1870.                                                 {
  1871.                                                     LONG Max = sizeof(struct PhoneHeader),Type;
  1872.  
  1873.                                                     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1874.                                                     {
  1875.                                                         if(SizeTable[Type - 1] > Max)
  1876.                                                             Max = SizeTable[Type - 1];
  1877.                                                     }
  1878.  
  1879.                                                     if(!(TempBuffer = AllocVecPooled(Max,MEMF_ANY)))
  1880.                                                     {
  1881.                                                         Error = ERR_NO_MEM;
  1882.  
  1883.                                                         Success = FALSE;
  1884.                                                     }
  1885.                                                 }
  1886.                                             }
  1887.                                         }
  1888.                                         else
  1889.                                             Success = TRUE;
  1890.  
  1891.                                         if(Success)
  1892.                                         {
  1893.                                             Success = FALSE;
  1894.  
  1895.                                             if(!(Error = PushChunk(Handle,0,ID_DIAL,IFFSIZE_UNKNOWN)))
  1896.                                             {
  1897.                                                 if(WriteChunkBytes(Handle,&NumPhoneEntries,sizeof(LONG)) == sizeof(LONG))
  1898.                                                 {
  1899.                                                     if(!(Error = PopChunk(Handle)))
  1900.                                                     {
  1901.                                                         if(!(Error = PopChunk(Handle)))
  1902.                                                         {
  1903.                                                             LONG i;
  1904.  
  1905.                                                             Success = TRUE;
  1906.  
  1907.                                                             for(i = 0 ; Success && i < NumPhoneEntries ; i++)
  1908.                                                             {
  1909.                                                                 Success = FALSE;
  1910.  
  1911.                                                                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1912.                                                                 {
  1913.                                                                     if(!(Error = PushChunk(Handle,0,ID_PHON,sizeof(struct PhoneHeader))))
  1914.                                                                     {
  1915.                                                                         if(TempBuffer)
  1916.                                                                         {
  1917.                                                                             Encrypt((UBYTE *)Phonebook[i] -> Header,sizeof(struct PhoneHeader),TempBuffer,PhonePassword,20);
  1918.  
  1919.                                                                             if(WriteChunkRecords(Handle,TempBuffer,sizeof(struct PhoneHeader),1) == 1)
  1920.                                                                             {
  1921.                                                                                 if(!(Error = PopChunk(Handle)))
  1922.                                                                                 {
  1923.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,TempBuffer,PhonePassword))
  1924.                                                                                     {
  1925.                                                                                         struct TimeDateNode *TimeDateNode;
  1926.  
  1927.                                                                                         Success = TRUE;
  1928.  
  1929.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1930.  
  1931.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1932.                                                                                         {
  1933.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  1934.                                                                                             {
  1935.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1936.                                                                                                 {
  1937.                                                                                                     Error = IoErr();
  1938.  
  1939.                                                                                                     Success = FALSE;
  1940.  
  1941.                                                                                                     break;
  1942.                                                                                                 }
  1943.                                                                                                 else
  1944.                                                                                                 {
  1945.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1946.                                                                                                     {
  1947.                                                                                                         Error = IoErr();
  1948.  
  1949.                                                                                                         Success = FALSE;
  1950.  
  1951.                                                                                                         break;
  1952.                                                                                                     }
  1953.                                                                                                 }
  1954.  
  1955.                                                                                                 if(Success)
  1956.                                                                                                 {
  1957.                                                                                                     if(Error = PopChunk(Handle))
  1958.                                                                                                     {
  1959.                                                                                                         Success = FALSE;
  1960.  
  1961.                                                                                                         break;
  1962.                                                                                                     }
  1963.                                                                                                 }
  1964.  
  1965.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1966.                                                                                             }
  1967.                                                                                         }
  1968.                                                                                     }
  1969.                                                                                     else
  1970.                                                                                     {
  1971.                                                                                         Error = IoErr();
  1972.  
  1973.                                                                                         Success = FALSE;
  1974.                                                                                     }
  1975.                                                                                 }
  1976.                                                                             }
  1977.                                                                             else
  1978.                                                                                 Error = IoErr();
  1979.                                                                         }
  1980.                                                                         else
  1981.                                                                         {
  1982.                                                                             if(WriteChunkRecords(Handle,Phonebook[i] -> Header,sizeof(struct PhoneHeader),1) == 1)
  1983.                                                                             {
  1984.                                                                                 if(!(Error = PopChunk(Handle)))
  1985.                                                                                 {
  1986.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,NULL,NULL))
  1987.                                                                                     {
  1988.                                                                                         struct TimeDateNode *TimeDateNode;
  1989.  
  1990.                                                                                         Success = TRUE;
  1991.  
  1992.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1993.  
  1994.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1995.                                                                                         {
  1996.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  1997.                                                                                             {
  1998.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1999.                                                                                                 {
  2000.                                                                                                     Error = IoErr();
  2001.  
  2002.                                                                                                     Success = FALSE;
  2003.  
  2004.                                                                                                     break;
  2005.                                                                                                 }
  2006.                                                                                                 else
  2007.                                                                                                 {
  2008.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  2009.                                                                                                     {
  2010.                                                                                                         Error = IoErr();
  2011.  
  2012.                                                                                                         Success = FALSE;
  2013.  
  2014.                                                                                                         break;
  2015.                                                                                                     }
  2016.                                                                                                 }
  2017.  
  2018.                                                                                                 if(Success)
  2019.                                                                                                 {
  2020.                                                                                                     if(Error = PopChunk(Handle))
  2021.                                                                                                     {
  2022.                                                                                                         Success = FALSE;
  2023.  
  2024.                                                                                                         break;
  2025.                                                                                                     }
  2026.                                                                                                 }
  2027.  
  2028.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  2029.                                                                                             }
  2030.                                                                                         }
  2031.                                                                                     }
  2032.                                                                                     else
  2033.                                                                                     {
  2034.                                                                                         Success = FALSE;
  2035.  
  2036.                                                                                         Error = IoErr();
  2037.                                                                                     }
  2038.                                                                                 }
  2039.                                                                             }
  2040.                                                                             else
  2041.                                                                                 Error = IoErr();
  2042.                                                                         }
  2043.                                                                     }
  2044.  
  2045.                                                                     if(Success)
  2046.                                                                     {
  2047.                                                                         if(PopChunk(Handle))
  2048.                                                                             Success = FALSE;
  2049.                                                                     }
  2050.                                                                 }
  2051.                                                             }
  2052.                                                         }
  2053.                                                     }
  2054.                                                 }
  2055.                                                 else
  2056.                                                     Error = IoErr();
  2057.                                             }
  2058.                                         }
  2059.  
  2060.                                         if(TempBuffer)
  2061.                                             FreeVecPooled(TempBuffer);
  2062.                                     }
  2063.                                 }
  2064.                                 else
  2065.                                     Error = IoErr();
  2066.                             }
  2067.                         }
  2068.  
  2069.                         if(Success)
  2070.                         {
  2071.                             if(Error = PopChunk(Handle))
  2072.                                 Success = FALSE;
  2073.                         }
  2074.                     }
  2075.  
  2076.                     CloseIFF(Handle);
  2077.                 }
  2078.  
  2079.                 Close(Handle -> iff_Stream);
  2080.             }
  2081.             else
  2082.                 Error = IoErr();
  2083.  
  2084.             FreeIFF(Handle);
  2085.         }
  2086.         else
  2087.             Error = ERR_NO_MEM;
  2088.  
  2089.         if(Success)
  2090.             AddProtection(Name,FIBF_EXECUTE);
  2091.         else
  2092.             DeleteFile(Name);
  2093.     }
  2094.  
  2095.     if(Error)
  2096.         SetIoErr(Error);
  2097.  
  2098.     return(Success);
  2099. }
  2100.  
  2101. STATIC BYTE
  2102. ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password)
  2103. {
  2104.     if(CreateConfigEntry(Config,Type))
  2105.     {
  2106.         APTR Data;
  2107.  
  2108.         switch(Type)
  2109.         {
  2110.             case PREF_SERIAL:
  2111.  
  2112.                 Data = Config -> SerialConfig;
  2113.                 break;
  2114.  
  2115.             case PREF_MODEM:
  2116.  
  2117.                 Data = Config -> ModemConfig;
  2118.                 break;
  2119.  
  2120.             case PREF_COMMAND:
  2121.  
  2122.                 Data = Config -> CommandConfig;
  2123.                 break;
  2124.  
  2125.             case PREF_SCREEN:
  2126.  
  2127.                 Data = Config -> ScreenConfig;
  2128.                 break;
  2129.  
  2130.             case PREF_TERMINAL:
  2131.  
  2132.                 Data = Config -> TerminalConfig;
  2133.                 break;
  2134.  
  2135.             case PREF_PATH:
  2136.  
  2137.                 Data = Config -> PathConfig;
  2138.                 break;
  2139.  
  2140.             case PREF_MISC:
  2141.  
  2142.                 Data = Config -> MiscConfig;
  2143.                 break;
  2144.  
  2145.             case PREF_CLIP:
  2146.  
  2147.                 Data = Config -> ClipConfig;
  2148.                 break;
  2149.  
  2150.             case PREF_CAPTURE:
  2151.  
  2152.                 Data = Config -> CaptureConfig;
  2153.                 break;
  2154.  
  2155.             case PREF_FILE:
  2156.  
  2157.                 Data = Config -> FileConfig;
  2158.                 break;
  2159.  
  2160.             case PREF_EMULATION:
  2161.  
  2162.                 Data = Config -> EmulationConfig;
  2163.                 break;
  2164.  
  2165.             case PREF_TRANSFER:
  2166.  
  2167.                 Data = Config -> TransferConfig;
  2168.                 break;
  2169.         }
  2170.  
  2171.         Len = MIN(SizeTable[Type - 1],Len);
  2172.  
  2173.         if(ReadChunkBytes(Handle,Data,Len) == Len)
  2174.         {
  2175.             if(Password)
  2176.                 Decrypt(Data,Len,Data,Password,20);
  2177.  
  2178.             if(Type == PREF_SCREEN)
  2179.                 FixScreenPens(Data);
  2180.  
  2181.             return(TRUE);
  2182.         }
  2183.     }
  2184.  
  2185.     return(FALSE);
  2186. }
  2187.  
  2188.     /* LoadPhonebook(STRPTR Name):
  2189.      *
  2190.      *    Restore a phone book from a disk file.
  2191.      */
  2192.  
  2193. BYTE __regargs
  2194. LoadPhonebook(STRPTR Name)
  2195. {
  2196.     struct PhoneEntry    **PrivatePhonebook;
  2197.     LONG             PrivatePhoneSize    = 0,
  2198.                  CurrentPhoneSize    = 0,
  2199.                  Count            = 0,
  2200.                  Index            = 0;
  2201.     BYTE             Success        = FALSE,
  2202.                  LastHadTime        = TRUE,
  2203.                  UsePhonePassword    = FALSE,
  2204.                  FirstChunk        = TRUE,
  2205.                  UseOld            = FALSE;
  2206.     struct IFFHandle    *Handle;
  2207.     struct ContextNode    *Chunk;
  2208.     struct TimeDateNode    *TimeDateNode;
  2209.     UBYTE             ConfigChunkType,
  2210.                  PasswordBuffer[20];
  2211.     BYTE             CheckedChunk = FALSE;
  2212.     LONG             Error = 0;
  2213.  
  2214.     if(Handle = AllocIFF())
  2215.     {
  2216.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  2217.         {
  2218.             InitIFFasDOS(Handle);
  2219.  
  2220.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  2221.             {
  2222.                 if(!(Error = StopChunks(Handle,(LONG *)Stops,NUM_STOPS)))
  2223.                 {
  2224.                     struct TermInfo TermInfo;
  2225.  
  2226.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  2227.                     {
  2228.                         Chunk = CurrentChunk(Handle);
  2229.  
  2230.                             /* Is this the first chunk to be read? */
  2231.  
  2232.                         if(!CheckedChunk)
  2233.                         {
  2234.                                 /* The first chunk must be a
  2235.                                  * catalog chunk, or this is
  2236.                                  * not a proper phonebook file.
  2237.                                  */
  2238.  
  2239.                             if(Chunk -> cn_ID != ID_CAT)
  2240.                                 break;
  2241.                             else
  2242.                                 CheckedChunk = TRUE;
  2243.                         }
  2244.  
  2245.                         if(Chunk -> cn_ID == ID_VERS)
  2246.                         {
  2247.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2248.                             {
  2249.                                 if(TermInfo . Version != CONFIG_FILE_VERSION || (TermInfo . Version == CONFIG_FILE_VERSION && TermInfo . Revision > CONFIG_FILE_REVISION))
  2250.                                 {
  2251.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  2252.                                         UseOld = TRUE;
  2253.  
  2254.                                     if(TermInfo . Version != 3)
  2255.                                         break;
  2256.                                 }
  2257.                             }
  2258.                             else
  2259.                             {
  2260.                                 Error = IoErr();
  2261.  
  2262.                                 break;
  2263.                             }
  2264.                         }
  2265.  
  2266.                         if(Chunk -> cn_ID == ID_PSWD)
  2267.                         {
  2268.                             if(ReadChunkBytes(Handle,PasswordBuffer,20) == 20)
  2269.                             {
  2270.                                 if(PhonePasswordUsed)
  2271.                                 {
  2272.                                     if(!memcmp(PhonePassword,PasswordBuffer,20))
  2273.                                     {
  2274.                                         UsePhonePassword = TRUE;
  2275.  
  2276.                                         continue;
  2277.                                     }
  2278.                                 }
  2279.  
  2280.                                 memset(SharedBuffer,0,21);
  2281.  
  2282.                                 if(GetString(FALSE,TRUE,21,LocaleString(MSG_PHONEPANEL_PLEASE_ENTER_PASSWORD_TXT),SharedBuffer))
  2283.                                 {
  2284.                                     UBYTE AnotherBuffer[20];
  2285.  
  2286.                                     Encrypt(SharedBuffer,20,AnotherBuffer,SharedBuffer,strlen(SharedBuffer));
  2287.  
  2288.                                     if(!memcmp(PasswordBuffer,AnotherBuffer,20))
  2289.                                     {
  2290.                                         UsePhonePassword = TRUE;
  2291.  
  2292.                                         continue;
  2293.                                     }
  2294.                                     else
  2295.                                     {
  2296.                                         MyEasyRequest(Window,LocaleString(MSG_TERMPHONE_WRONG_PASSWORD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Name);
  2297.  
  2298.                                         break;
  2299.                                     }
  2300.                                 }
  2301.                                 else
  2302.                                     break;
  2303.                             }
  2304.                             else
  2305.                             {
  2306.                                 Error = IoErr();
  2307.  
  2308.                                 break;
  2309.                             }
  2310.                         }
  2311.  
  2312.                         if(Chunk -> cn_ID == ID_DIAL)
  2313.                         {
  2314.                             if(ReadChunkBytes(Handle,&CurrentPhoneSize,sizeof(LONG)) == sizeof(LONG))
  2315.                             {
  2316.                                 if(!CurrentPhoneSize)
  2317.                                     break;
  2318.                                 else
  2319.                                 {
  2320.                                     if(!(PrivatePhonebook = CreatePhonebook(CurrentPhoneSize,&PrivatePhoneSize,TRUE)))
  2321.                                     {
  2322.                                         Error = ERR_NO_MEM;
  2323.  
  2324.                                         break;
  2325.                                     }
  2326.                                 }
  2327.                             }
  2328.                             else
  2329.                             {
  2330.                                 Error = IoErr();
  2331.  
  2332.                                 break;
  2333.                             }
  2334.                         }
  2335.  
  2336.                         if(Chunk -> cn_ID == ID_PHON)
  2337.                         {
  2338.                             WORD Size = MIN(sizeof(struct PhoneHeader),Chunk -> cn_Size);
  2339.  
  2340.                             if(!CurrentPhoneSize)
  2341.                                 break;
  2342.  
  2343.                             if(!LastHadTime)
  2344.                             {
  2345.                                 if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  2346.                                     AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2347.                             }
  2348.  
  2349.                             if(!FirstChunk)
  2350.                                 Index++;
  2351.                             else
  2352.                                 FirstChunk = FALSE;
  2353.  
  2354.                             if(ReadChunkBytes(Handle,PrivatePhonebook[Index] -> Header,Size) == Size)
  2355.                             {
  2356.                                 if(UsePhonePassword)
  2357.                                     Decrypt((UBYTE *)PrivatePhonebook[Index] -> Header,Size,(UBYTE *)PrivatePhonebook[Index] -> Header,PasswordBuffer,20);
  2358.  
  2359.                                 PrivatePhonebook[Index] -> Count = -1;
  2360.  
  2361.                                 LastHadTime = FALSE;
  2362.  
  2363.                                 Count++;
  2364.                             }
  2365.                             else
  2366.                             {
  2367.                                 Error = IoErr();
  2368.  
  2369.                                 break;
  2370.                             }
  2371.                         }
  2372.  
  2373.                         if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  2374.                         {
  2375.                             if(!CurrentPhoneSize)
  2376.                                 break;
  2377.  
  2378.                             if(UsePhonePassword)
  2379.                             {
  2380.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,PasswordBuffer))
  2381.                                 {
  2382.                                     if(Count)
  2383.                                         CurrentPhoneSize = Count - 1;
  2384.                                     else
  2385.                                         CurrentPhoneSize = 0;
  2386.  
  2387.                                     break;
  2388.                                 }
  2389.                                 else
  2390.                                     FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE,TermInfo . Version,TermInfo . Revision);
  2391.                             }
  2392.                             else
  2393.                             {
  2394.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  2395.                                 {
  2396.                                     if(Count)
  2397.                                         CurrentPhoneSize = Count - 1;
  2398.                                     else
  2399.                                         CurrentPhoneSize = 0;
  2400.  
  2401.                                     break;
  2402.                                 }
  2403.                                 else
  2404.                                     FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE,TermInfo . Version,TermInfo . Revision);
  2405.                             }
  2406.                         }
  2407.  
  2408.                         if(Chunk -> cn_ID == ID_DATE)
  2409.                         {
  2410.                             WORD Count = (Chunk -> cn_Size - sizeof(struct TimeDateHeader)) / sizeof(struct TimeDate);
  2411.  
  2412.                             if(!CurrentPhoneSize)
  2413.                                 break;
  2414.  
  2415.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",Count))
  2416.                             {
  2417.                                 if(ReadChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) == sizeof(struct TimeDateHeader))
  2418.                                 {
  2419.                                     if(ReadChunkRecords(Handle,TimeDateNode -> Table,sizeof(struct TimeDate),Count) == Count)
  2420.                                     {
  2421.                                         AdaptTimeDateNode(TimeDateNode);
  2422.  
  2423.                                         AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2424.  
  2425.                                         LastHadTime = TRUE;
  2426.                                     }
  2427.                                     else
  2428.                                     {
  2429.                                         Error = IoErr();
  2430.  
  2431.                                         FreeTimeDateNode(TimeDateNode);
  2432.                                     }
  2433.                                 }
  2434.                                 else
  2435.                                 {
  2436.                                     Error = IoErr();
  2437.  
  2438.                                     FreeTimeDateNode(TimeDateNode);
  2439.                                 }
  2440.                             }
  2441.                         }
  2442.                     }
  2443.  
  2444.                     if(CurrentPhoneSize)
  2445.                     {
  2446.                         LONG i;
  2447.  
  2448.                         if(!LastHadTime)
  2449.                         {
  2450.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  2451.                                 AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2452.                         }
  2453.  
  2454.                         if(Phonebook)
  2455.                             DeletePhonebook(Phonebook,PhoneSize,TRUE);
  2456.  
  2457.                         Phonebook    = PrivatePhonebook;
  2458.                         PhoneSize    = PrivatePhoneSize;
  2459.                         NumPhoneEntries    = CurrentPhoneSize;
  2460.                         Success        = TRUE;
  2461.  
  2462.                         memcpy(PhonePassword,PasswordBuffer,20);
  2463.                         PhonePasswordUsed = UsePhonePassword;
  2464.  
  2465.                         for(i = NumPhoneEntries ; i < PhoneSize ; i++)
  2466.                         {
  2467.                             if(Phonebook[i])
  2468.                             {
  2469.                                 if(Phonebook[i] -> Config)
  2470.                                     DeleteConfiguration(Phonebook[i] -> Config);
  2471.  
  2472.                                 FreeVecPooled(Phonebook[i]);
  2473.  
  2474.                                 Phonebook[i] = NULL;
  2475.                             }
  2476.                         }
  2477.  
  2478.                         FreeDialList(TRUE);
  2479.  
  2480.                         for(i = 0 ; i < NumPhoneEntries ; i++)
  2481.                             FinalFix(Phonebook[i] -> Config,TRUE,TermInfo . Version,TermInfo . Revision);
  2482.                     }
  2483.                     else
  2484.                     {
  2485.                         if(PrivatePhoneSize)
  2486.                         {
  2487.                             DeletePhonebook(PrivatePhonebook,PrivatePhoneSize,TRUE);
  2488.  
  2489.                             Success = FALSE;
  2490.                         }
  2491.                     }
  2492.                 }
  2493.  
  2494.                 CloseIFF(Handle);
  2495.             }
  2496.  
  2497.             Close(Handle -> iff_Stream);
  2498.         }
  2499.         else
  2500.             Error = IoErr();
  2501.  
  2502.         FreeIFF(Handle);
  2503.     }
  2504.     else
  2505.         Error = ERR_NO_MEM;
  2506.  
  2507.     if(Error)
  2508.         SetIoErr(Error);
  2509.  
  2510.     if(UseOld)
  2511.         return(LoadOldPhonebook(Name));
  2512.     else
  2513.         return(Success);
  2514. }
  2515.  
  2516.     /* WriteConfig(STRPTR Name,struct Configuration *Config):
  2517.      *
  2518.      *    Write the configuration to a file, very much like
  2519.      *    WriteIFFData().
  2520.      */
  2521.  
  2522. BYTE __regargs
  2523. WriteConfig(STRPTR Name,struct Configuration *Config)
  2524. {
  2525.     struct IFFHandle    *Handle;
  2526.     BYTE             Success = FALSE;
  2527.     LONG             Error = 0;
  2528.  
  2529.         /* Allocate a handle. */
  2530.  
  2531.     if(Handle = AllocIFF())
  2532.     {
  2533.             /* Open an output stream. */
  2534.  
  2535.         if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  2536.         {
  2537.                 /* Tell iffparse that this is
  2538.                  * a DOS handle.
  2539.                  */
  2540.  
  2541.             InitIFFasDOS(Handle);
  2542.  
  2543.                 /* Open the handle for writing. */
  2544.  
  2545.             if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  2546.             {
  2547.                     /* Push outmost chunk onto stack. */
  2548.  
  2549.                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  2550.                 {
  2551.                         /* Add a version identifier. */
  2552.  
  2553.                     if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  2554.                     {
  2555.                         struct TermInfo TermInfo;
  2556.  
  2557.                         TermInfo . Version    = CONFIG_FILE_VERSION;
  2558.                         TermInfo . Revision    = CONFIG_FILE_REVISION;
  2559.  
  2560.                             /* Update the other configuration pointer as well. */
  2561.  
  2562.                         Config -> SerialConfig -> LastVersionSaved    = TermVersion;
  2563.                         Config -> SerialConfig -> LastRevisionSaved    = TermRevision;
  2564.  
  2565.                             /* Write the version data. */
  2566.  
  2567.                         if(WriteChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2568.                         {
  2569.                                 /* Pop the version chunk, i.e. write it to the file. */
  2570.  
  2571.                             if(Error = PopChunk(Handle))
  2572.                                 Success = FALSE;
  2573.                             else
  2574.                             {
  2575.                                 if(WriteConfigChunks(Handle,Config,NULL,NULL))
  2576.                                 {
  2577.                                     LONG i;
  2578.  
  2579.                                     Success = TRUE;
  2580.  
  2581.                                     for(i = 0 ; Success && i < WINDOW_COUNT ; i++)
  2582.                                     {
  2583.                                         if(!(Error = PushChunk(Handle,0,ID_WINF,sizeof(struct WindowInfo))))
  2584.                                         {
  2585.                                             if(WriteChunkBytes(Handle,&WindowInfoTable[i],sizeof(struct WindowInfo)) == sizeof(struct WindowInfo))
  2586.                                             {
  2587.                                                 if(Error = PopChunk(Handle))
  2588.                                                     Success = FALSE;
  2589.                                             }
  2590.                                             else
  2591.                                             {
  2592.                                                 Error = IoErr();
  2593.  
  2594.                                                 Success = FALSE;
  2595.                                             }
  2596.                                         }
  2597.                                         else
  2598.                                             Success = FALSE;
  2599.                                     }
  2600.                                 }
  2601.                             }
  2602.                         }
  2603.                         else
  2604.                         {
  2605.                             Error = IoErr();
  2606.  
  2607.                             Success = FALSE;
  2608.                         }
  2609.                     }
  2610.  
  2611.                         /* Seems that we're done, now try to pop the FORM chunk
  2612.                          * and return.
  2613.                          */
  2614.  
  2615.                     if(Success)
  2616.                     {
  2617.                         if(Error = PopChunk(Handle))
  2618.                             Success = FALSE;
  2619.                     }
  2620.                 }
  2621.  
  2622.                     /* Close the handle (flush any pending data). */
  2623.  
  2624.                 CloseIFF(Handle);
  2625.             }
  2626.  
  2627.                 /* Close the DOS handle itself. */
  2628.  
  2629.             Close(Handle -> iff_Stream);
  2630.         }
  2631.         else
  2632.             Error = IoErr();
  2633.  
  2634.             /* And free the IFF handle. */
  2635.  
  2636.         FreeIFF(Handle);
  2637.     }
  2638.     else
  2639.         Error = ERR_NO_MEM;
  2640.  
  2641.     if(Success)
  2642.         AddProtection(Name,FIBF_EXECUTE);
  2643.  
  2644.     return(Success);
  2645. }
  2646.  
  2647.     /* ReadConfig(STRPTR Name,struct Configuration *Config):
  2648.      *
  2649.      *    Read the configuration file, very much the same as ReadIFFData().
  2650.      */
  2651.  
  2652. BYTE __regargs
  2653. ReadConfig(STRPTR Name,struct Configuration *Config)
  2654. {
  2655.     struct IFFHandle    *Handle;
  2656.     BYTE             Success    = FALSE,
  2657.                  UseOld        = FALSE;
  2658.     struct ContextNode    *Chunk;
  2659.     UBYTE             ConfigChunkType;
  2660.     LONG             Error = 0;
  2661.  
  2662.     if(Handle = AllocIFF())
  2663.     {
  2664.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  2665.         {
  2666.             InitIFFasDOS(Handle);
  2667.  
  2668.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  2669.             {
  2670.                 if(!StopChunks(Handle,(LONG *)Stops,NUM_STOPS))
  2671.                 {
  2672.                     struct TermInfo TermInfo;
  2673.  
  2674.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  2675.                     {
  2676.                         Chunk = CurrentChunk(Handle);
  2677.  
  2678.                             /* Oops! Some is trying to
  2679.                              * use the phone book file as
  2680.                              * a configuration file.
  2681.                              */
  2682.  
  2683.                         if(Chunk -> cn_ID == ID_CAT)
  2684.                         {
  2685.                             Success = FALSE;
  2686.  
  2687.                             break;
  2688.                         }
  2689.  
  2690.                         if(Chunk -> cn_ID == ID_VERS)
  2691.                         {
  2692.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2693.                             {
  2694.                                 if(TermInfo . Version != CONFIG_FILE_VERSION || (TermInfo . Version == CONFIG_FILE_VERSION && TermInfo . Revision > CONFIG_FILE_REVISION))
  2695.                                 {
  2696.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  2697.                                         UseOld = TRUE;
  2698.  
  2699.                                     if(TermInfo . Version != 3)
  2700.                                         break;
  2701.                                 }
  2702.                             }
  2703.                             else
  2704.                             {
  2705.                                 Error = IoErr();
  2706.  
  2707.                                 break;
  2708.                             }
  2709.                         }
  2710.  
  2711.                         if(Chunk -> cn_ID == ID_WINF)
  2712.                         {
  2713.                             struct WindowInfo Info;
  2714.  
  2715.                             if(ReadChunkBytes(Handle,&Info,sizeof(Info)) == sizeof(Info))
  2716.                             {
  2717.                                 Success = TRUE;
  2718.  
  2719.                                 ReplaceWindowInfo(&Info);
  2720.                             }
  2721.                             else
  2722.                             {
  2723.                                 Error = IoErr();
  2724.  
  2725.                                 Success = FALSE;
  2726.                                 break;
  2727.                             }
  2728.                         }
  2729.                         else
  2730.                         {
  2731.                             if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  2732.                             {
  2733.                                 if(ReadConfigChunk(Handle,Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  2734.                                 {
  2735.                                     FixOldConfig(Config,ConfigChunkType,FALSE,TermInfo . Version,TermInfo . Revision);
  2736.  
  2737.                                     Success = TRUE;
  2738.                                 }
  2739.                                 else
  2740.                                 {
  2741.                                     Error = IoErr();
  2742.  
  2743.                                     Success = FALSE;
  2744.  
  2745.                                     break;
  2746.                                 }
  2747.                             }
  2748.                         }
  2749.                     }
  2750.  
  2751.                     if(Success)
  2752.                         FinalFix(Config,FALSE,TermInfo . Version,TermInfo . Revision);
  2753.                 }
  2754.  
  2755.                 CloseIFF(Handle);
  2756.             }
  2757.  
  2758.             Close(Handle -> iff_Stream);
  2759.         }
  2760.  
  2761.         FreeIFF(Handle);
  2762.     }
  2763.     else
  2764.         Error = IoErr();
  2765.  
  2766.     if(Error)
  2767.         SetIoErr(Error);
  2768.  
  2769.     if(UseOld)
  2770.         return(ReadOldConfig(Name,Config));
  2771.     else
  2772.         return(Success);
  2773. }
  2774.